package com.panshi.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
@Slf4j
public class exceptionController {
    //UnauthorizedException 未授权异常
    @ExceptionHandler(value = UnauthorizedException.class)//处理访问方法时权限不足问题
    public String defaultErrorHandler(HttpServletRequest req, Exception e)  {
        return "/error/noauth";
    }

    //
    @ExceptionHandler(value = UnauthenticatedException.class)//处理访问方法时权限不足问题
    public String defaultErrorHandler(HttpServletRequest req, UnauthenticatedException e)  {
        log.info("非法访问===>uri={}",req.getRequestURI());
        return "/error/illegality";
    }

    @ExceptionHandler(value = Exception.class)//处理访问方法时权限不足问题
    public String defaultExceptionHandler(HttpServletRequest req, Exception e)  {
        log.info("xxxxxxxxxxxxxxxx===>{}",e);
        return "/error/500";
    }
}